<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->

<!doctype html>
<html>
<head>
  <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
  <title>mqtt-connection-events</title>

  <script src="../../webcomponentsjs/webcomponents.min.js"></script>
  <script src="../../web-component-tester/browser.js"></script>
  <script src="../../test-fixture/test-fixture-mocha.js"></script>

  <!-- Step 1: import the element to test -->
  <link rel="import" href="../../polymer/polymer.html">
  <link rel="import" href="../../promise-polyfill/promise-polyfill-lite.html">
  <link rel="import" href="../../test-fixture/test-fixture.html">

  <link rel="import" href="../mqtt-elements.html">

</head>
<body>

<test-fixture id="Connection">
  <template>
    <mqtt-connection></mqtt-connection>
  </template>
</test-fixture>

<script>
  var mqttElement;
  suite('<mqtt-connection>', function () {
    suite('mqtt-connection-events', function () {
      setup(function () {
        mqttElement = fixture('Connection');
      });

      //  Setp 3: Test the element
      test('calling _handelConnected should fire a `mqtt-connection-connected` event', function (done) {
        mqttElement.addEventListener('mqtt-connection-connected', function () {
          done();
        });
        mqttElement._handelConnected();
      });

      test('calling _handelReconnect should fire a `mqtt-connection-reconnect` event', function (done) {
        mqttElement.addEventListener('mqtt-connection-reconnect', function () {
          done();
        });
        mqttElement._handelReconnect();
      });

      test('calling _handelClose should fire a `mqtt-connection-close` event', function (done) {
        mqttElement.addEventListener('mqtt-connection-close', function () {
          done();
        });
        mqttElement._handelClose();
      });

      test('calling _handelOffline should fire a `mqtt-connection-offline` event', function (done) {
        mqttElement.addEventListener('mqtt-connection-offline', function () {
          done();
        });
        mqttElement._handelOffline();
      });

      test('calling _handelError should fire a `mqtt-connection-error` event', function (done) {
        mqttElement.addEventListener('mqtt-connection-error', function () {
          done();
        });
        mqttElement._handelError();
      });

      test('calling _handelMessage should fire a `mqtt-message` event', function (done) {
        mqttElement.addEventListener('mqtt-message', function () {
          done();
        });
        // Generating a test message/ packet
        var message = {};
        var packet = {};
        mqttElement._handelMessage("mqttjs/test/message", message, packet);
      });

    });
  });
</script>

</body>
</html>
